package Level03;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * 东方教育包含 2 个班级:Java 基础班,Java 就业班
 * Java 基础班:
 * 001 李晨
 * 002 范冰冰
 * Java 就业班:
 * 001 马云
 * 002 马化腾
 * 使用 HashMap 嵌套 HashMap 方式完成,1 使用 keySet 和增强 for 遍历出里面的元素,2 使用
 * entrySet 和迭代器遍历出里面的元素
 */
public class Two {
    public static void main(String[] args) {
        HashMap<String,HashMap<Object,Object>> hashMap = new HashMap<>();
        HashMap<Object, Object> basic = new HashMap<>();
        basic.put("001","李晨");
        basic.put("002","范冰冰");
        HashMap<Object, Object> employment = new HashMap<>();
        employment.put("001","马云");
        employment.put("002","马化腾");
        hashMap.put("Java 基础班",basic);
        hashMap.put("Java 就业班",employment);
        //使用 keySet 和增强 for 遍历出里面的元素
        for (String classroom : hashMap.keySet()) {
            HashMap<Object, Object> students = hashMap.get(classroom);
            for (Object id : students.keySet()) {
                System.out.println(classroom+"-->"+id+students.get(id));
            }
        }
        System.out.println("--------------------");
        //使用entrySet 和迭代器遍历出里面的元素
        Set<Map.Entry<String, HashMap<Object, Object>>> entries = hashMap.entrySet();
        Iterator<Map.Entry<String, HashMap<Object, Object>>> iterator = entries.iterator();
        while (iterator.hasNext()){
            Map.Entry<String, HashMap<Object, Object>> next = iterator.next();
            System.out.println(next.getKey());
            System.out.println(next.getValue());
        }
    }
}
